package YAPserver;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * Manages a list of every game played.
 * @author DMiagi
 *
 */
public class PlayedGames {

	private static List<PlayedGames> playedGames= Collections.synchronizedList(new ArrayList<PlayedGames>());
	
	private final String lobbyName;
	private final String[] players;
	
	private PlayedGames(String lobbyName, String[] players){
		this.lobbyName=lobbyName;
		this.players=players;
	}
	
	private String getName(){
		return lobbyName;
	}
	
	private String getPlayers(){
		String string="";
		for(int i=0; i<players.length-1; i++)
			string+= players[i]+", ";
		string+=players[players.length-1];
		return string;
	}
	
	/**
	 * Adds a game as played to a server's internal list.
	 * @param lobbyName
	 * @param players
	 */
	public static void addGame(String lobbyName, String[] players){
		playedGames.add(new PlayedGames(lobbyName, players));
	}
	
	/**
	 * Returns every played game.
	 * @return all the played games in one string
	 */
	public static String getPlayedGames(){
		String string="";
		for(PlayedGames pG: playedGames){
			string+=pG.getName()+": "+pG.getPlayers()+"\n";
		}
		return string;
	}
}
